﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:MvvmLightSL.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using System.ServiceModel.DomainServices.Client;
using GSSoftSL.Design;
using GSSoftSL.Model;
using GSSoftSL.ViewModel.HocVienVM;
using GSSoftSL.Web.Services;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;

namespace GSSoftSL.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class ViewModelLocator
    {
        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignModeStatic)
            {
                //SimpleIoc.Default.Register<IDataService, DesignDataService>();
                SimpleIoc.Default.Register<GSSoftContext, GSSoftContext>();
            }
            else
            {
                //SimpleIoc.Default.Register<IDataService, DataService>();
                //SimpleIoc.Default.Register<DomainContext, GSSoftContext>();
                //var t = ServiceLocator.Current.GetInstance<IDataService>();
                //var dc1 = ServiceLocator.Current.GetInstance<DomainContext>();
                SimpleIoc.Default.Register<DomainContext>(() => new GSSoftContext());
                //var _dc = ServiceLocator.Current.GetInstance<DomainContext>();
                SimpleIoc.Default.Register<DomainContext>(() => new GSSoftContext(), "HocVien");
            }

            //SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<TruongViewModel>();
            SimpleIoc.Default.Register<PhongViewModel>();
            SimpleIoc.Default.Register<MonViewModel>();
            SimpleIoc.Default.Register<GiaoVienViewModel>();
            SimpleIoc.Default.Register<LopViewModel>();
            SimpleIoc.Default.Register<CaHocViewModel>();
            SimpleIoc.Default.Register<KhoaHocViewModel>();
            SimpleIoc.Default.Register(() => new HocVienMainViewModel(),"HocVien");
            SimpleIoc.Default.Register(() => new HocVienEditViewModel(),"HocVien");
            SimpleIoc.Default.Register(() => new HocVienKhoaHocViewModel(), "HocVien");
            SimpleIoc.Default.Register(() => new HocVienHocPhiViewModel(),"HocVien");
            SimpleIoc.Default.Register(() => new DiemDanhViewModel(),"DiemDanh");
            SimpleIoc.Default.Register(() => new DiemSoViewModel(),"DiemSo");
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TruongViewModel Truong
        {
            get
            {
                return ServiceLocator.Current.GetInstance<TruongViewModel>();
                //return new TruongViewModel(new GSSoftContext());
            }
        }

        public PhongViewModel Phong
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PhongViewModel>();
            }
        }

        public MonViewModel Mon
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MonViewModel>();
            }
        }

        public GiaoVienViewModel GiaoVien
        {
            get
            {
                return ServiceLocator.Current.GetInstance<GiaoVienViewModel>();
            }
        }

        public LopViewModel Lop
        {
            get
            {
                return ServiceLocator.Current.GetInstance<LopViewModel>();
            }
        }

        public CaHocViewModel CaHoc
        {
            get
            {
                return ServiceLocator.Current.GetInstance<CaHocViewModel>();
            }
        }

        public KhoaHocViewModel KhoaHoc
        {
            get
            {
                return ServiceLocator.Current.GetInstance<KhoaHocViewModel>();
            }
        }

        public HocVienMainViewModel HocVienMain
        {
            get
            {
                return ServiceLocator.Current.GetInstance<HocVienMainViewModel>("HocVien");
            }
        }

        public HocVienKhoaHocViewModel HocVienKhoaHoc
        {
            get
            {
                return ServiceLocator.Current.GetInstance<HocVienKhoaHocViewModel>("HocVien");
            }
        }

        public HocVienHocPhiViewModel HocVienHocPhi
        {
            get
            {
                return ServiceLocator.Current.GetInstance<HocVienHocPhiViewModel>("HocVien");
            }
        }

        public DiemDanhViewModel DiemDanh
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DiemDanhViewModel>("DiemDanh");
            }
        }

        public DiemSoViewModel DiemSo
        {
            get
            {
                return ServiceLocator.Current.GetInstance<DiemSoViewModel>("DiemSo");
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
        }
    }
}